package cn.airfei.netty.nio;

import java.nio.ByteBuffer;

/**
 * @description:
 * @author: air
 * @create: 2020-12-31 11:16
 */
public class ReadOnlyBuffer {

    public static void main(String[] args) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(128);
        for (int i=0;i<128;i++){
            byteBuffer.put((byte) i);
        }

        byteBuffer.flip();

//        while (byteBuffer.hasRemaining()){
//            System.out.println(byteBuffer.get());
//        }

        ByteBuffer readOnlyBuffer = byteBuffer.asReadOnlyBuffer();
        System.out.println("*************** 我是优雅的分割线 **************");

        while (readOnlyBuffer.hasRemaining()){
            System.out.println(readOnlyBuffer.get());
        }

        readOnlyBuffer.put((byte) 9);
    }

}
